package com.trkj.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.trkj.service.CcCasrhistoryService;
import com.trkj.vo.CcCasrhistoryVo;
import com.trkj.vo.HospVo;
import com.trkj.vo.Result;

@Controller
public class CcCasrhistoryController {

	@Autowired
	private CcCasrhistoryService cccService;
////
	@RequestMapping("/cc_toshowEtongji")
	public @ResponseBody Map<String, Object> showEtongji() {
		return cccService.tongjiE();
	}

	@RequestMapping("/cc_totongEadmissiondate")
	public @ResponseBody Map<String, Object> cctongjiByadmissiondate() {
		return cccService.tongjiEadmissiondate();
	}
	@RequestMapping("/cc_toshowtongji")
	public void showtongji(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// ModelAndView mv = new ModelAndView();
		List<HospVo> list = cccService.tongji();
		String start = "<chart caption='科室住院记录统计' " + "xaxisname='部门' yaxisname='病人人数' "
				+ "palettecolors='#FFFACD' bgcolor='#ffffff' " + "borderalpha='0'	canvasborderalpha='0' "
				+ "useplotgradientcolor='0' " + "plotborderalpha='10' placevaluesinside='1' "
				+ "rotatevalues='10' valuefontcolor='#000000' " + "showxaxisline='10' xaxislinecolor='#999999' "
				+ "divlinecolor='#999999' divlinedashed='10' " + "showalternatehgridcolor='0' subcaptionfontbold='0' "
				+ "	subcaptionfontsize='12'>";
		String sets = "";
		for (HospVo a : list) {
			sets += "<set label='" + a.getName() + "' value='" + a.getValue() + "' color='#33CCFF' />";
		}
		String end = "</chart>";
		String all = start + sets + end;
		response.setContentType("text/plain;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println(all);
		out.close();
	}

	@RequestMapping("/ccto_queryByAllCcCasrhistory")
	public @ResponseBody Map<String, Object> queryByAll(int page, int rows) {
		return cccService.queryByAll(page, rows);
	}

	@RequestMapping("/ccto_delCcCasrhistory")
	public @ResponseBody Result delCcCasrhistory(long[] list) {
		int y = cccService.delCcCasrhistory(list);
		return new Result(true, "你共选择了" + list.length + "条记录，其中有" + y + "条符合该操作的要求，已成功完成操作！");
	}

	@RequestMapping("/ccto_queryByCcCasrhistoryqueryBypname")
	public @ResponseBody List<CcCasrhistoryVo> queryBypname(String pname) {
		return cccService.queryByCasepatientid(pname);
	}

	@RequestMapping("/cc_totongjiByadmissiondate")
	public void tongjiByadmissiondate(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// ModelAndView mv = new ModelAndView();
		List<HospVo> list = cccService.tongjiByadmissiondate();
		Date date = new Date();
		String strdate = date.getYear() + 1900 + "";
		String start = "<chart caption='" + strdate + "年度住院记录统计' " + "xaxisname='月份' yaxisname='病人人数' "
				+ "palettecolors='#FFFACD' bgcolor='#ffffff' " + "borderalpha='0'	canvasborderalpha='0' "
				+ "useplotgradientcolor='0' " + "plotborderalpha='10' placevaluesinside='1' "
				+ "rotatevalues='10' valuefontcolor='#000000' " + "showxaxisline='10' xaxislinecolor='#999999' "
				+ "divlinecolor='#999999' divlinedashed='10' " + "showalternatehgridcolor='0' subcaptionfontbold='0' "
				+ "	subcaptionfontsize='12'>";
		String sets = "";
		for (HospVo a : list) {
			sets += "<set label='" + a.getName() + "' value='" + a.getValue() + "' color='#33CCFF' />";
		}
		String end = "</chart>";
		String all = start + sets + end;
		response.setContentType("text/plain;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println(all);
		out.close();
	}
}
